﻿using System;
using BalanceManager.Helpers;
using BalanceManager.ViewModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTests
{
    [TestClass]
    public class DateUtilsTests
    {
        [TestMethod]
        public void GetBegginingOfWeekForDate_ForMonday()
        {
            var date = new DateTime(2014, 03, 10);
            var expected = date;

            var actual = DateUtils.GetBegginingOfWeekForDate(date);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void GetBegginingOfWeekForDate_ForTuesday()
        {
            var date = new DateTime(2014, 03, 11);
            var expected = new DateTime(2014, 03, 10);

            var actual = DateUtils.GetBegginingOfWeekForDate(date);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void GetBegginingOfWeekForDate_ForWednesday()
        {
            var date = new DateTime(2014, 03, 12);
            var expected = new DateTime(2014, 03, 10);

            var actual = DateUtils.GetBegginingOfWeekForDate(date);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void GetBegginingOfWeekForDate_ForThursday()
        {
            var date = new DateTime(2014, 03, 13);
            var expected = new DateTime(2014, 03, 10);

            var actual = DateUtils.GetBegginingOfWeekForDate(date);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void GetBegginingOfWeekForDate_ForFriday()
        {
            var date = new DateTime(2014, 03, 14);
            var expected = new DateTime(2014, 03, 10);

            var actual = DateUtils.GetBegginingOfWeekForDate(date);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void GetBegginingOfWeekForDate_ForSaturday()
        {
            var date = new DateTime(2014, 03, 15);
            var expected = new DateTime(2014, 03, 10);

            var actual = DateUtils.GetBegginingOfWeekForDate(date);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void GetBegginingOfWeekForDate_ForSunday()
        {
            var date = new DateTime(2014, 03, 16);
            var expected = new DateTime(2014, 03, 10);

            var actual = DateUtils.GetBegginingOfWeekForDate(date);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void GetStartAndEndDateByPeriod_Today()
        {
            var date = new DateTime(2014, 03, 14);
            var expectedStartDate = new DateTime(2014, 03, 14, 0, 0, 0, 0);
            var expectedEndDate = new DateTime(2014, 03, 14, 23, 59, 59, 999);

            DateTime actualStartDate;
            DateTime actualEndDate;
            DateUtils.GetStartAndEndDateByPeriod(date, Period.Today, out actualStartDate, out actualEndDate);

            Assert.AreEqual(expectedStartDate, actualStartDate);
            Assert.AreEqual(expectedEndDate, actualEndDate);
        }

        [TestMethod]
        public void GetStartAndEndDateByPeriod_Yesterday()
        {
            var date = new DateTime(2014, 03, 14);
            var expectedStartDate = new DateTime(2014, 03, 13, 0, 0, 0, 0);
            var expectedEndDate = new DateTime(2014, 03, 14, 23, 59, 59, 999);

            DateTime actualStartDate;
            DateTime actualEndDate;
            DateUtils.GetStartAndEndDateByPeriod(date, Period.Yesterday, out actualStartDate, out actualEndDate);

            Assert.AreEqual(expectedStartDate, actualStartDate);
            Assert.AreEqual(expectedEndDate, actualEndDate);
        }

        [TestMethod]
        public void GetStartAndEndDateByPeriod_Week()
        {
            var date = new DateTime(2014, 03, 14);
            var expectedStartDate = new DateTime(2014, 03, 10, 0, 0, 0, 0);
            var expectedEndDate = new DateTime(2014, 03, 14, 23, 59, 59, 999);

            DateTime actualStartDate;
            DateTime actualEndDate;
            DateUtils.GetStartAndEndDateByPeriod(date, Period.Week, out actualStartDate, out actualEndDate);

            Assert.AreEqual(expectedStartDate, actualStartDate);
            Assert.AreEqual(expectedEndDate, actualEndDate);
        }

        [TestMethod]
        public void GetStartAndEndDateByPeriod_Month()
        {
            var date = new DateTime(2014, 03, 14);
            var expectedStartDate = new DateTime(2014, 03, 01, 0, 0, 0, 0);
            var expectedEndDate = new DateTime(2014, 03, 14, 23, 59, 59, 999);

            DateTime actualStartDate;
            DateTime actualEndDate;
            DateUtils.GetStartAndEndDateByPeriod(date, Period.Month, out actualStartDate, out actualEndDate);

            Assert.AreEqual(expectedStartDate, actualStartDate);
            Assert.AreEqual(expectedEndDate, actualEndDate);
        }

        [TestMethod]
        public void GetStartAndEndDateByPeriod_Year()
        {
            var date = new DateTime(2014, 03, 14);
            var expectedStartDate = new DateTime(2014, 01, 01, 0, 0, 0, 0);
            var expectedEndDate = new DateTime(2014, 03, 14, 23, 59, 59, 999);

            DateTime actualStartDate;
            DateTime actualEndDate;
            DateUtils.GetStartAndEndDateByPeriod(date, Period.Year, out actualStartDate, out actualEndDate);

            Assert.AreEqual(expectedStartDate, actualStartDate);
            Assert.AreEqual(expectedEndDate, actualEndDate);
        }
    }
}
